package com.zhkj.txg.module.home.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.zhkj.txg.module.home.entity.BannerEntity
import com.zhkj.txg.utils.ImageUtils
import com.youth.banner.adapter.BannerAdapter
import com.zhkj.txg.R

class HomeBannerAdapter(
    private val context: Context
) : BannerAdapter<BannerEntity, BannerViewHolder>(null) {
    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_home_banner_image, parent, false).apply {
            layoutParams =
                ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        }
        val imageView = ImageView(context).apply {
            layoutParams =
                ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
            scaleType = ImageView.ScaleType.MATRIX
        }
        return BannerViewHolder(view)
    }

    override fun onBindView(holder: BannerViewHolder?, data: BannerEntity?, position: Int, size: Int) {
        holder?.let { ImageUtils.loadImage(context, it.img, data?.image ?: "") }
    }
}

class BannerViewHolder(view: View) : RecyclerView.ViewHolder(view) {
    val img = itemView.findViewById<ImageView>(R.id.ivBannerImage)
}